<template>
  <div>
    <div class="margin-top">
      <label>抵扣金额：</label>
      <el-input-number
        v-model="data.deductionCount"
        :min="100"
        :step="100"
        :max="100000"
      />
    </div>
    <div class="ep-btn-group">
      <el-button @click="resetForm">取消</el-button>
      <el-button type="primary" @click="addded">添加</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, defineEmits } from "vue";
import { DedAdd } from "@/api/Vip/Deductions";
import { toast } from "@/tools/tools";

const data = reactive({
  deductionCount: 1,
});

//添加抵扣
const emit = defineEmits(["update:visible"]);
const addded = async () => {
  const res = await DedAdd(data);
  if (res.code >= 0) {
    toast.success(res.message);
    emit("update:visible", false); // 保存成功后关闭对话框
  } else {
    toast.error(res.message);
  }
};

//取消
const resetForm = () => {
  emit("update:visible", false); // 关闭对话框
};
</script>

<style scoped>
.ep-btn-group {
  margin-top: 30px;
  text-align: right;
  margin-right: 30px;
  margin-bottom: 10px;
}
.margin-top {
  margin-top: 10px;
}
</style>
